package com.onepiece.shipelves.common.myutils.tree;

import java.util.ArrayList;
import java.util.List;

//主要是迭代比较要拿到要进行比较的节点l的left和r的right，这样的话，也可以使用辅助的数据结构如队列或栈，存储要比较的

/**
 while (!st.empty()) {
 TreeNode* leftNode = st.top(); st.pop();
 TreeNode* rightNode = st.top(); st.pop();
 if (!leftNode && !rightNode) {
 continue;
 }
 if ((!leftNode || !rightNode || (leftNode->val != rightNode->val))) {
 return false;
 }
 st.push(leftNode->left);
 st.push(rightNode->right);
 st.push(leftNode->right);
 st.push(rightNode->left);
 }

 */
public class isSymmetric {
    public boolean isSymmetric(TreeNode root) {
        return root == null ? true : recur(root.left, root.right);
    }
    boolean recur(TreeNode L, TreeNode R) {
        if(L == null && R == null) return true;
        if(L == null || R == null || L.val != R.val) return false;
        return recur(L.left, R.right) && recur(L.right, R.left);
    }




}
